package Multithreading.Exercise012;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * ClassName:ThreadDome
 * Package:Multithreading.Exercise012
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/3/7-16:33
 * @Version:v1.0
 */
public class ThreadDome {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list,10,5,20,50,100,200,500,800,2,80,300,700);

        //创建多线程要运行的参数对象
        MyCallable mc = new MyCallable(list);

        //创建多线程运行结果的管理对象
        FutureTask<Integer> ft1 = new FutureTask<>(mc);
        FutureTask<Integer> ft2 = new FutureTask<>(mc);

        Thread t1 = new Thread(ft1);
        Thread t2 = new Thread(ft2);

        t1.setName("抽奖箱1");
        t2.setName("抽奖箱2");

        t1.start();
        t2.start();

        int max1 = ft1.get();
        int max2 = ft2.get();

        System.out.println("线程1的最大奖项金额为："+max1);
        System.out.println("线程2的最大奖项金额为："+max2);
    }
}
